package com.itheima.convertedio;

import java.io.*;
import java.util.ArrayList;

public class ConvertedDemo7 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        Student s1 = new Student("杜紫藤", 16);
        Student s2 = new Student("张三", 23);
        Student s3 = new Student("李四", 24);

        ArrayList<Student> students = new ArrayList<Student>();
        students.add(s1);
        students.add(s2);
        students.add(s3);

        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("a.txt"));
        oos.writeObject(students);

        oos.close();

        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("a.txt"));
        ArrayList<Student> studentlist2 = (ArrayList<Student>) ois.readObject();
        studentlist2.forEach(s-> System.out.println(s));

        ois.close();
    }
}
